//食物对象
// 属性 : 宽和高 还有背景颜色 x y 轴坐标
//方法 : 可以移动  随机生成
function Food(options) {
    options = options || {};
    this.width = options.width || 20;
    this.height = options.height || 20;
    this.bgc = options.bgc || 'blue';
    this.x = options.x || 0;
    this.y = options.y || 0;
}
Food.prototype.render = function(target) {
    //创建一个食物
    var div = document.createElement('div');
    div.style.width = this.width + 'px';
    div.style.height = this.height + 'px';
    div.style.backgroundColor = this.bgc;
    div.style.position = 'absolute';
    this.x = parseInt(Math.random() * target.offsetWidth / this.width);
    this.y = parseInt(Math.random() * target.offsetHeight / this.height);
    div.style.left = this.x * this.width + 'px';
    div.style.top = this.y * this.height + 'px';
    target.appendChild(div);
}